package com.xjrsoft.module.customerTwo.AppManage.business_opportunity.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.page.ConventPage;
import java.util.List;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.base.service.IXjrBaseCodeRuleService;
import com.xjrsoft.module.customerTwo.AppManage.business_opportunity.dto.BusinessOpportunityLogDto;
import com.xjrsoft.module.customerTwo.AppManage.business_opportunity.dto.SaveBusinessOpportunityLogFormDataDto;
import com.xjrsoft.module.customerTwo.AppManage.business_opportunity.vo.BusinessOpportunityLogVo;
import com.xjrsoft.module.customerTwo.AppManage.business_opportunity.vo.BusinessOpportunityLogListVo;
import com.xjrsoft.module.customerTwo.AppManage.business_opportunity.dto.BusinessOpportunityLogListDto;
import com.xjrsoft.core.secure.utils.SecureUtil;
import com.xjrsoft.core.tool.utils.FlowableUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

import org.springframework.web.bind.annotation.*;
import com.xjrsoft.module.customerTwo.AppManage.business_opportunity.entity.BusinessOpportunityLog;
import com.xjrsoft.module.customerTwo.AppManage.business_opportunity.service.IBusinessOpportunityLogService;

/**
 *  控制器
 *
 * @author lisen
 * @since 2024-04-25
 */
@RestController
@AllArgsConstructor
@RequestMapping("/business_opportunity")
@Api(value = "商机", tags = "商机接口")
public class BusinessOpportunityLogController {


	private final IBusinessOpportunityLogService businessOpportunityLogService;

	private final IXjrBaseCodeRuleService codeRuleService;

	/**
	 * 详情 
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入businessOpportunityLog")
	@SaCheckPermission(value = {"business_opportunity:view", "business_opportunity:modify"}, mode = SaMode.OR)
	public Response<BusinessOpportunityLogVo> getFormData(@PathVariable String id) {
		// 主表数据
		BusinessOpportunityLog businessOpportunityLog = businessOpportunityLogService.getById(id);
		BusinessOpportunityLogVo businessOpportunityLogVo = BeanUtil.copy(businessOpportunityLog, BusinessOpportunityLogVo.class);
		return Response.ok(businessOpportunityLogVo);
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping
	@ApiOperation(value = "分页", notes = "传入businessOpportunityLog")
		public Response<PageOutput<BusinessOpportunityLogListVo>> getPageList(BusinessOpportunityLogListDto listDto) {
		IPage<BusinessOpportunityLog> page = businessOpportunityLogService.getPageList(listDto);
		List<BusinessOpportunityLogListVo> records = BeanUtil.copyList(page.getRecords(), BusinessOpportunityLogListVo.class);
			// 工作流数据处理
		FlowableUtil.systemFormList(records, SecureUtil.getModuleId());
		return Response.ok(ConventPage.getPageOutput(page.getTotal(), records));
	}

	/**
	 * 新增 
	 */
	@PostMapping
	@ApiOperation(value = "新增", notes = "传入businessOpportunityLog")
	public Response save(@RequestParam String assemblyId) {
		Integer dataId = businessOpportunityLogService.addBusinessOpportunityLog(assemblyId);
		if (dataId != null) {
			codeRuleService.useEncode("BusinessOpportunityCode");
		}
		return dataId == null ? Response.notOk() : Response.ok(dataId);
	}

	/**
	 * 修改 
	 */
	@PutMapping("/{id}")
	@ApiOperation(value = "修改", notes = "传入businessOpportunityLog")
	@SaCheckPermission("business_opportunity:modify")
	public Response update(@PathVariable String id, @RequestBody SaveBusinessOpportunityLogFormDataDto formDto) {
		BusinessOpportunityLogDto businessOpportunityLogDto = formDto.getBusinessOpportunityLogDto();
		BusinessOpportunityLog businessOpportunityLog = BeanUtil.copy(businessOpportunityLogDto, BusinessOpportunityLog.class);
		return Response.status(businessOpportunityLogService.updateBusinessOpportunityLog(id, businessOpportunityLog));
	}



	/**
	 * 删除 
	 */
	@DeleteMapping("/{ids}")
	@ApiOperation(value = "删除", notes = "传入ids")
	@SaCheckPermission(value = {"business_opportunity:batchDelete", "business_opportunity:delete"}, mode = SaMode.OR)
	public Response remove(@ApiParam(value = "主键集合", required = true) @PathVariable String ids) {
		return Response.status(businessOpportunityLogService.delete(ids));
	}


}
